package com.horsen.service.edu.service.impl;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.horsen.service.edu.listener.SubjectExcelListener;
import com.horsen.service.edu.mapper.SubjectMapper;
import com.horsen.service.edu.model.BO.SubjectInputBO;
import com.horsen.service.edu.model.Subject;
import com.horsen.service.edu.model.VO.SubjectChartVO;
import com.horsen.service.edu.model.VO.SubjectVO;
import com.horsen.service.edu.service.SubjectService;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.util.List;

/**
 * 科目 服务实现类
 *
 * @author Horsen
 * @since 2021-04-06
 */
@Service
public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> implements SubjectService {
    /**
     * 批量导入
     *
     * @param inputStream 输入流
     */
    @Override
    public void batchImport(InputStream inputStream) {
        EasyExcel.read(inputStream, SubjectInputBO.class, new SubjectExcelListener(baseMapper))
                .sheet().doRead();
    }

    /**
     * 获取科目树形列表
     *
     * @return 树形列表
     */
    @Override
    public List<SubjectVO> getTreeList() {
        return baseMapper.selectTreeListByParentId("0");
    }

    /**
     * 获取二级科目数
     *
     * @return 科目数
     */
    @Override
    public Integer countSecondarySubject() {
        LambdaQueryWrapper<Subject> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.ne(Subject::getParentId, 0);
        return baseMapper.selectCount(queryWrapper);
    }

    /**
     * 获取科目饼状图数据
     *
     * @return 科目饼状图VO
     */
    @Override
    public List<SubjectChartVO> getChartValue() {
        return baseMapper.getChartValue();
    }
}
